package com.hr;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.espirit.EntityMapping;
import com.espirit.common.VersionAware;
import com.espirit.eap.annotation.Dict;
import com.espirit.eap.annotation.DomainModel;
import com.espirit.eap.manager.Department;
import com.espirit.eap.sa.Employee;
import com.espirit.eap.sa.EmployeeAware;
import com.espirit.eap.sa.User;
import com.espirit.finance.core.AcctTerm;
import com.espirit.finance.core.AcctTermCheckAware;
import com.googlecode.cswish.model.Saas;

@Entity
@DomainModel
public class DutyRecord extends EntityMapping implements Serializable, EmployeeAware, VersionAware, AcctTermCheckAware, Saas{
	private static final long serialVersionUID = 8978210857030744298L;
	
	public static final String STATE = "dutyrecord_state";
	public static final Integer STATE_NORMAL = 1;
	public static final Integer STATE_WAIT_APPROVE = 0;
	
	public static final String TYPE = "dutyrecord_type";
	
	public static final Integer TYPE_NORMAL = 1;
	public static final Integer TYPE_DUTY = 2;
	public static final Integer TYPE_FORGET = 3;
	public static final Integer TYPE_SUBSTITUTE = 4;
	
	private Integer sid;
	public Integer getSid() {
		return sid;
	}

	public void setSid(Integer sid) {
		this.sid = sid;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	public User getCreated() {
		return created;
	}
	public void setCreated(User created) {
		this.created = created;
	}

	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	public Date getDutyTime() {
		return dutyTime;
	}
	public void setDutyTime(Date dutyOn) {
		this.dutyTime = dutyOn;
	}
	
	@Dict(type=STATE)
	public Integer getState() {
		return state;
	}
	public void setState(Integer state) {
		this.state = state;
	}
	
	@Transient
	public String getDeptIds() {
		return deptIds;
	}
	public void setDeptIds(String deptIds) {
		this.deptIds = deptIds;
	}

	@Dict(type=TYPE)
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}

	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}

	private Employee employee;
	private Date dutyTime;
	private Integer state;
	

	private Department department;
	private User created;
	private Date createdOn;
	private String deptIds;
	private Integer type;
	private String userId;

	@Override
	public boolean check(AcctTerm acctTerm) {
		if (acctTerm != null && acctTerm.getBeginDate() != null && this.dutyTime != null){
			return acctTerm.getBeginDate().compareTo(this.dutyTime) < 0;
		} else {
			return true;
		}
	}
}
